package com.ruoyi.system.mc.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.mc.entity.BaseMsgEnum;
import com.ruoyi.system.mc.entity.McShopCart;
import com.ruoyi.system.mc.mapper.McShopCartMapper;
import com.ruoyi.system.mc.service.McShopCartService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

/*
 *  @author 雨安
 *  类名： McShopCartServiceImpl
 *  创建时间：2024/5/29
 */
@Service
public class McShopCartServiceImpl extends ServiceImpl<McShopCartMapper, McShopCart> implements McShopCartService {

    //购物车表Service层
    @Resource
    private McShopCartService mcShopCartService;

    /**
     * 新增语句
     * @param mcShopCart 新增对象
     * @return 返回新增结果
     */
    @Override
    public String insertShopCar(McShopCart mcShopCart) {
        System.out.println(mcShopCart + "测试lkasjflkas");
        //判断添加对象不为null
        if (Objects.nonNull(mcShopCart)){
            //创建日期格式对象
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            //设置商品对应的商家ID
            mcShopCart.setUserId(SecurityUtils.getLoginUser().getUserId());
            //设置一些默认值
            mcShopCart.setCreateBy(SecurityUtils.getUsername());
            mcShopCart.setCreateTime(java.sql.Date.valueOf(sdf.format(new Date())));
            mcShopCart.setUpdateBy(SecurityUtils.getUsername());
            mcShopCart.setUpdateTime(java.sql.Date.valueOf(sdf.format(new Date())));
            mcShopCart.setDeleteFlag(Boolean.FALSE);
            //执行添加方法
            Boolean save = mcShopCartService.save(mcShopCart);
            //返回提示结果字符串
            return save == true ? BaseMsgEnum.SHOPSUCCESS.getGetMsg() : BaseMsgEnum.ERROR.getGetMsg();
        }else{
            //返回操作失败提示
            return BaseMsgEnum.ERROR.getGetMsg();
        }
    }






}
